//
//  StringUtil.m
//  AlgorithmDemo
//
//  Created by zxs on 2020/8/20.
//  Copyright © 2020 zxs. All rights reserved.
//

#import "StringUtil.h"

@implementation StringUtil

// 字符串反转
void reverse(char *string) {
    // 指向第一个字符
    char *begin = string;
    // 指向最后一个字符
    char *end = string + strlen(string) - 1;
    
    while (begin < end) {
        // 交换前后两个字符
        char temp = *begin;
        *begin = *end;
        *end = temp;
        // 移动指针
        begin++;
        end--;
    }
}

// 包含中文的倒序；试验下来不成功
// https://zhidao.baidu.com/question/546085242.html
unsigned char *InverseStr(unsigned char t[],unsigned char s[]) {
    int i,j,len = (int)strlen((char *)s);
    for(i = len - 1,j = 0; i >= 0; --i,++j) {
    if(s[i] > 0X7F) { // 是汉字
    t[j++] = s[i - 1];
    t[j] = s[i];
    --i;
    }
    else t[j] = s[i];
    }
    t[j] = '\0';
    return t;
}

@end
